/*
 * Copyright (c) 2005 -2008 Reliable Source, Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Mozilla Public License v.1.1,
 * BSD, and Eclipse Public License v1.0 which accompanies this
 * distribution and is available at:
 *
 * 		http://www.eclipse.org/legal/epl-v10.html
 * 		http://www.opensource.org/licenses/bsd-license.php
 * 		http://www.mozilla.org/MPL/MPL-1.1.html
 *
 * Contributors:
 *     IBM Corporation	     -  http://ibm.com
 *     	- initial API and implementation
 *
 *     patientos.org         - http://patientos.org
 *     	- domain and database persistence layer
 *
 *     Reliable Source, Inc. - http://reliablesource.org
 *     	- Symbiosys Application Framework,
 *     	- Symbiosys Application, Symbiosys Product
 *
 */
package org.reliablesource.symbiosys.ui.tests.viewers;

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

import org.reliablesource.model.core.IReliableElement;
import org.reliablesource.model.core.IReliableNode;

import org.reliablesource.symbiosys.workbench.tests.TestPlugin;

import java.util.Collection;


/**
 *
 * MockObjectContentProvider.java<br>
 * Created on: Jun 26, 2008<br>
 *
 * @author <a href="mailto:dennis.park@gmail.com"> Dennis Park</a>
 *
 *
 * @category
 * @since 1.0
 */
public class MockObjectContentProvider implements ITreeContentProvider {
    /*
     * (non-Javadoc)
     * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
     */
    public Object[] getChildren(final Object _parentElement) {
        if (_parentElement instanceof IReliableNode)
            return ((IReliableNode) _parentElement).getChildren();

        return TestPlugin.NULL_OBJECT;
    }

    /*
     * (non-Javadoc)
     * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
     */
    public Object getParent(final Object _element) {
        if (_element instanceof IReliableElement)
            return ((IReliableElement) _element).getParent();

        return TestPlugin.NULL_OBJECT;
    }

    /*
     * (non-Javadoc)
     * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
     */
    public boolean hasChildren(final Object _element) {
        if (_element instanceof IReliableNode)
            return ((IReliableNode) _element).getChildren().length > 0;

        return false;
    }

    /*
     * (non-Javadoc)
     * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
     */
    public Object[] getElements(final Object _inputElement) {
        if (_inputElement instanceof Collection)
            return ((Collection<?>) _inputElement).toArray();
        else if (hasChildren(_inputElement))
            return getChildren(_inputElement);

        return TestPlugin.NULL_OBJECT;
    }

    /*
     * (non-Javadoc)
     * @see org.eclipse.jface.viewers.IContentProvider#dispose()
     */
    public void dispose() {
    }

    /*
     * (non-Javadoc)
     * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
     */
    public void inputChanged(Viewer _viewer, Object oldInput, Object newInput) {
    }
}
